package com.chance.cc.crawler.development.command.node;

import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * created by CC on 2020/11/26
 * mail 279020185@qq.com
 */
@Slf4j
public class CrawlerDomainCommand extends com.chance.cc.crawler.development.command.HttpCommand {

    public CrawlerDomainCommand(String host, int port){
        super(host,port);
    }

    public HttpPage killXHSArticleInitJob(String crawlerListQueueName){
        String url = commandUrl("/kill/xhs/article/init/job");

        HttpRequest request = new HttpRequest();
        request.setUrl(url+"?crawlerListQueueName="+crawlerListQueueName);

        HttpPage httpPage = doCommand(request);
        log.info("response result :" + httpPage.getRawText());
        return httpPage;
    }

    public HttpPage killXHSRealTimeCommentInitJob(String crawlerArticleIdsQueueName){
        String url = commandUrl("/kill/xhs/realtime/comment/init/job");

        HttpRequest request = new HttpRequest();
        request.setUrl(url+"?crawlerArticleIdsQueueName="+crawlerArticleIdsQueueName);

        HttpPage httpPage = doCommand(request);
        log.info("response result :" + httpPage.getRawText());
        return httpPage;
    }

    @Override
    public String initUrlPrefix(String host,int port) {
        return StringUtils.join("http://",host,":",port,"/crawler/domain/common/api/v1");
    }
}
